package cn.itcast.day03;

import java.util.ArrayList;
import java.util.Random;

public class Demo04ArrayListReturn {
    public static void main(String[] args) {
        ArrayList<Integer> bigList = new ArrayList<>();
//        ArrayList<Integer> smallList = new ArrayList<>();

        Random r = new Random();

        for (int i = 0; i < 20; i++) {

            int num = r.nextInt(100) + 1;
            bigList.add(num);
            System.out.println(num);
        }
        System.out.println("==========");
//        System.out.println(filtrateEvenNum(bigList));
        ArrayList<Integer> smallList = filtrateEvenNum(bigList);
        System.out.println("偶数总共有" + smallList.size() + "个");
        for (int i = 0; i < smallList.size(); i++) {
            System.out.println(smallList.get(i));
        }
    }

    public static ArrayList<Integer> filtrateEvenNum(ArrayList<Integer> list) {
        ArrayList<Integer> smallList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i) % 2 == 0) {
                smallList.add(list.get(i));
            }
        }
        return smallList;
    }
}
